package c.e.a.b.f.b;

import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import c.e.a.b.b.j.b;
import c.e.a.b.b.j.c;
import c.e.a.b.b.j.d;
import c.e.a.b.e.c.c2;
import c.e.a.b.e.c.k2;
import c.e.a.b.e.c.l2;
import c.e.a.b.e.c.s2;
import c.e.a.b.e.c.t2;
import c.e.a.b.e.c.v1;
import c.e.a.b.e.c.v8;
import c.e.a.b.e.c.y1;
import com.google.android.gms.internal.measurement.zzae;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

/* compiled from: com.google.android.gms:play-services-measurement-impl@@18.0.0 */
public class u4 implements t5 {
    public static volatile u4 H;
    public volatile Boolean A;
    public Boolean B;
    public Boolean C;
    public volatile boolean D;
    public int E;
    public AtomicInteger F = new AtomicInteger(0);
    public final long G;
    public final Context a;
    public final String b;
    public final String c;
    public final String d;
    public final boolean e;
    public final ga f;
    public final c g;
    public final d4 h;
    public final q3 i;
    public final r4 j;
    public final w8 k;
    public final t9 l;
    public final o3 m;
    public final b n;
    public final h7 o;
    public final c6 p;
    public final a q;
    public final d7 r;
    public m3 s;
    public q7 t;
    public j u;
    public n3 v;
    public m4 w;
    public boolean x = false;
    public Boolean y;
    public long z;

    public u4(y5 y5Var) {
        long longValue;
        int i = 0;
        Context context = y5Var.a;
        ga gaVar = new ga();
        this.f = gaVar;
        d.f = gaVar;
        this.a = context;
        this.b = y5Var.b;
        this.c = y5Var.c;
        this.d = y5Var.d;
        this.e = y5Var.h;
        this.A = y5Var.e;
        this.D = true;
        zzae zzae = y5Var.g;
        if (zzae != null) {
            Bundle bundle = zzae.g;
            if (bundle != null) {
                Object obj = bundle.get("measurementEnabled");
                if (obj instanceof Boolean) {
                    this.B = (Boolean) obj;
                }
                Object obj2 = zzae.g.get("measurementDeactivated");
                if (obj2 instanceof Boolean) {
                    this.C = (Boolean) obj2;
                }
            }
        }
        synchronized (l2.g) {
            t2 t2Var = l2.h;
            Context applicationContext = context.getApplicationContext();
            if (applicationContext == null) {
                applicationContext = context;
            }
            if (t2Var == null || t2Var.a() != applicationContext) {
                y1.d();
                s2.c();
                synchronized (c2.class) {
                    c2 c2Var = c2.c;
                    if (c2Var != null) {
                        Context context2 = c2Var.a;
                        if (!(context2 == null || c2Var.b == null)) {
                            context2.getContentResolver().unregisterContentObserver(c2.c.b);
                        }
                    }
                    c2.c = null;
                }
                l2.h = new v1(applicationContext, d.r(new k2(applicationContext)));
                l2.j.incrementAndGet();
            }
        }
        this.n = c.a;
        Long l = y5Var.i;
        if (l != null) {
            longValue = l.longValue();
        } else {
            longValue = System.currentTimeMillis();
        }
        this.G = longValue;
        this.g = new c(this);
        d4 d4Var = new d4(this);
        d4Var.p();
        this.h = d4Var;
        q3 q3Var = new q3(this);
        q3Var.p();
        this.i = q3Var;
        t9 t9Var = new t9(this);
        t9Var.p();
        this.l = t9Var;
        o3 o3Var = new o3(this);
        o3Var.p();
        this.m = o3Var;
        this.q = new a(this);
        h7 h7Var = new h7(this);
        h7Var.u();
        this.o = h7Var;
        c6 c6Var = new c6(this);
        c6Var.u();
        this.p = c6Var;
        w8 w8Var = new w8(this);
        w8Var.u();
        this.k = w8Var;
        d7 d7Var = new d7(this);
        d7Var.p();
        this.r = d7Var;
        r4 r4Var = new r4(this);
        r4Var.p();
        this.j = r4Var;
        zzae zzae2 = y5Var.g;
        if (!(zzae2 == null || zzae2.b == 0)) {
            i = 1;
        }
        i ^= 1;
        if (context.getApplicationContext() instanceof Application) {
            c6 s = s();
            if (s.a.a.getApplicationContext() instanceof Application) {
                Application application = (Application) s.a.a.getApplicationContext();
                if (s.c == null) {
                    s.c = new y6(s, null);
                }
                if (i != 0) {
                    application.unregisterActivityLifecycleCallbacks(s.c);
                    application.registerActivityLifecycleCallbacks(s.c);
                    s.d().n.a("Registered activity lifecycle callback");
                }
            }
        } else {
            d().i.a("Application context is not an Application");
        }
        r4Var.v(new w4(this, y5Var));
    }

    public static u4 f(Context context, zzae zzae, Long l) {
        if (zzae != null && (zzae.e == null || zzae.f == null)) {
            zzae = new zzae(zzae.a, zzae.b, zzae.c, zzae.d, null, null, zzae.g);
        }
        Objects.requireNonNull(context, "null reference");
        Objects.requireNonNull(context.getApplicationContext(), "null reference");
        if (H == null) {
            synchronized (u4.class) {
                if (H == null) {
                    H = new u4(new y5(context, zzae, l));
                }
            }
        } else if (zzae != null) {
            Bundle bundle = zzae.g;
            if (bundle != null && bundle.containsKey("dataCollectionDefaultEnabled")) {
                H.A = Boolean.valueOf(zzae.g.getBoolean("dataCollectionDefaultEnabled"));
            }
        }
        return H;
    }

    public static void g(s5 s5Var) {
        if (s5Var == null) {
            throw new IllegalStateException("Component not created");
        }
    }

    public static void p(a5 a5Var) {
        if (a5Var == null) {
            throw new IllegalStateException("Component not created");
        } else if (!a5Var.b) {
            String valueOf = String.valueOf(a5Var.getClass());
            StringBuilder stringBuilder = new StringBuilder(valueOf.length() + 27);
            stringBuilder.append("Component not initialized: ");
            stringBuilder.append(valueOf);
            throw new IllegalStateException(stringBuilder.toString());
        }
    }

    public static void q(r5 r5Var) {
        if (r5Var == null) {
            throw new IllegalStateException("Component not created");
        } else if (!r5Var.n()) {
            String valueOf = String.valueOf(r5Var.getClass());
            StringBuilder stringBuilder = new StringBuilder(valueOf.length() + 27);
            stringBuilder.append("Component not initialized: ");
            stringBuilder.append(valueOf);
            throw new IllegalStateException(stringBuilder.toString());
        }
    }

    public final a A() {
        a aVar = this.q;
        if (aVar != null) {
            return aVar;
        }
        throw new IllegalStateException("Component not created");
    }

    public final boolean B() {
        return this.A != null && this.A.booleanValue();
    }

    public final r4 a() {
        q(this.j);
        return this.j;
    }

    public final b b() {
        return this.n;
    }

    public final c c() {
        return this.g;
    }

    public final q3 d() {
        q(this.i);
        return this.i;
    }

    public final Context e() {
        return this.a;
    }

    public final ga h() {
        return this.f;
    }

    public final boolean i() {
        return j() == 0;
    }

    public final int j() {
        a().g();
        if (this.g.x()) {
            return 1;
        }
        Boolean bool = this.C;
        if (bool != null && bool.booleanValue()) {
            return 2;
        }
        if (v8.a() && this.g.o(p.H0) && !k()) {
            return 8;
        }
        bool = o().x();
        if (bool == null) {
            bool = this.g.w("firebase_analytics_collection_enabled");
            if (bool == null) {
                bool = this.B;
                if (bool != null) {
                    if (bool.booleanValue()) {
                        return 0;
                    }
                    return 5;
                } else if (c.e.a.b.b.g.a.b.a("isMeasurementExplicitlyDisabled").c) {
                    return 6;
                } else {
                    if (!this.g.o(p.S) || this.A == null || this.A.booleanValue()) {
                        return 0;
                    }
                    return 7;
                }
            } else if (bool.booleanValue()) {
                return 0;
            } else {
                return 4;
            }
        } else if (bool.booleanValue()) {
            return 0;
        } else {
            return 3;
        }
    }

    public final boolean k() {
        a().g();
        return this.D;
    }

    public final void l() {
        throw new IllegalStateException("Unexpected call on client side");
    }

    /* JADX WARNING: Missing block: B:9:0x0033, code skipped:
            if (java.lang.Math.abs(android.os.SystemClock.elapsedRealtime() - r6.z) > 1000) goto L_0x0035;
     */
    /* JADX WARNING: Missing block: B:29:0x00c1, code skipped:
            if (android.text.TextUtils.isEmpty(r0.l) == false) goto L_0x00c3;
     */
    public final boolean m() {
        /*
        r6 = this;
        r0 = r6.x;
        if (r0 == 0) goto L_0x00d1;
    L_0x0004:
        r0 = r6.a();
        r0.g();
        r0 = r6.y;
        if (r0 == 0) goto L_0x0035;
    L_0x000f:
        r1 = r6.z;
        r3 = 0;
        r5 = (r1 > r3 ? 1 : (r1 == r3 ? 0 : -1));
        if (r5 == 0) goto L_0x0035;
    L_0x0017:
        r0 = r0.booleanValue();
        if (r0 != 0) goto L_0x00ca;
    L_0x001d:
        r0 = r6.n;
        r0 = (c.e.a.b.b.j.c) r0;
        java.util.Objects.requireNonNull(r0);
        r0 = android.os.SystemClock.elapsedRealtime();
        r2 = r6.z;
        r0 = r0 - r2;
        r0 = java.lang.Math.abs(r0);
        r2 = 1000; // 0x3e8 float:1.401E-42 double:4.94E-321;
        r4 = (r0 > r2 ? 1 : (r0 == r2 ? 0 : -1));
        if (r4 <= 0) goto L_0x00ca;
    L_0x0035:
        r0 = r6.n;
        r0 = (c.e.a.b.b.j.c) r0;
        java.util.Objects.requireNonNull(r0);
        r0 = android.os.SystemClock.elapsedRealtime();
        r6.z = r0;
        r0 = r6.t();
        r1 = "android.permission.INTERNET";
        r0 = r0.p0(r1);
        r1 = 0;
        r2 = 1;
        if (r0 == 0) goto L_0x0082;
    L_0x0050:
        r0 = r6.t();
        r3 = "android.permission.ACCESS_NETWORK_STATE";
        r0 = r0.p0(r3);
        if (r0 == 0) goto L_0x0082;
    L_0x005c:
        r0 = r6.a;
        r0 = c.e.a.b.b.k.b.a(r0);
        r0 = r0.c();
        if (r0 != 0) goto L_0x0080;
    L_0x0068:
        r0 = r6.g;
        r0 = r0.C();
        if (r0 != 0) goto L_0x0080;
    L_0x0070:
        r0 = r6.a;
        r0 = c.e.a.b.f.b.n4.a(r0);
        if (r0 == 0) goto L_0x0082;
    L_0x0078:
        r0 = r6.a;
        r0 = c.e.a.b.f.b.t9.U(r0);
        if (r0 == 0) goto L_0x0082;
    L_0x0080:
        r0 = 1;
        goto L_0x0083;
    L_0x0082:
        r0 = 0;
    L_0x0083:
        r0 = java.lang.Boolean.valueOf(r0);
        r6.y = r0;
        r0 = r0.booleanValue();
        if (r0 == 0) goto L_0x00ca;
    L_0x008f:
        r0 = r6.t();
        r3 = r6.z();
        r3.t();
        r3 = r3.k;
        r4 = r6.z();
        r4.t();
        r4 = r4.l;
        r5 = r6.z();
        r5.t();
        r5 = r5.m;
        r0 = r0.c0(r3, r4, r5);
        if (r0 != 0) goto L_0x00c3;
    L_0x00b4:
        r0 = r6.z();
        r0.t();
        r0 = r0.l;
        r0 = android.text.TextUtils.isEmpty(r0);
        if (r0 != 0) goto L_0x00c4;
    L_0x00c3:
        r1 = 1;
    L_0x00c4:
        r0 = java.lang.Boolean.valueOf(r1);
        r6.y = r0;
    L_0x00ca:
        r0 = r6.y;
        r0 = r0.booleanValue();
        return r0;
    L_0x00d1:
        r0 = new java.lang.IllegalStateException;
        r1 = "AppMeasurement is not initialized";
        r0.<init>(r1);
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.a.b.f.b.u4.m():boolean");
    }

    public final d7 n() {
        q(this.r);
        return this.r;
    }

    public final d4 o() {
        g(this.h);
        return this.h;
    }

    public final w8 r() {
        p(this.k);
        return this.k;
    }

    public final c6 s() {
        p(this.p);
        return this.p;
    }

    public final t9 t() {
        g(this.l);
        return this.l;
    }

    public final o3 u() {
        g(this.m);
        return this.m;
    }

    public final boolean v() {
        return TextUtils.isEmpty(this.b);
    }

    public final h7 w() {
        p(this.o);
        return this.o;
    }

    public final q7 x() {
        p(this.t);
        return this.t;
    }

    public final j y() {
        q(this.u);
        return this.u;
    }

    public final n3 z() {
        p(this.v);
        return this.v;
    }
}
